﻿using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for SummaryForm.xaml
    /// </summary>
    /// 
    public partial class JLTAB50BS
    {
        CollectionViewSource vwEvents
        {
            get
            {
                return (CollectionViewSource)this.FindResource("vwEvents");
            }
        }
        DataRow dwEvents
        {
            get
            {
                if (vwEvents.View == null)
                    return null;
                if (vwEvents.View.CurrentItem == null)
                    return null;
                return ((DataRowView)vwEvents.View.CurrentItem).Row;
            }
        }
        void vwEvents_CurrentChanged(object sender, EventArgs e)
        {
            try
            {
                if (dwEvents == null)
                    return;
                SwithWorkFlow(dwEvents);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return;
        }
        public void SwithWorkFlow(DataRow dwInput)
        {

            
        }
        public override void OnWorkflowIDChange(string wfid)
        {
            base.OnWorkflowIDChange(wfid);
            try
            {
                dwWFEvent = null;
                DataSet SResult = INTEXDBC.QueryICC_WFEVENTS(wfid, 1);
                foreach (DataRow row in SResult.Tables[0].Rows)
                {
                    dwWFEvent = row;
                }
                if (dwWFEvent == null)
                    return;
                btnWFRefresh_Click(null, null);
                SwithWorkFlow(dwWFEvent);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        private void btnWFRefresh_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                /*
                SetProd.ICC_WFEVENTS.Clear();
                SetProd.Merge(m_Data.QueryWFEVENTS(dwWFEvent));
                */
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }


        private void EVENTS_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            ComboBox cb = sender as ComboBox;
            if (cb.SelectedValue == null)
                return;
            //txtEvents.Text = (cb.SelectedValue).ToString();
        }
        private void Apply(DataRow rowEvents)
        {
            try
            {
                DataRow dwData = null;
                string msg = "";
                string events = rowEvents["WFEVENTS"].ToString().Trim();
                MessageInfo msgs = new MessageInfo();
                switch (events)
                {
                    case "MYGRVKPOS001"://品质审核               
                    case "MYGRVKPOS002"://颜色审核
                    case "MYGRVKPOS003"://计划备料审核
                    case "MYGRVKPOS004"://运输
                    case "MYGRVKPOS005"://计划
                    case "MYGRVKPOS006"://生产
                    case "MYGRVKPOS007"://销售
                        msg = Helpers.Helper.ConvertGB2312To8859P1(rowEvents["WFEDES"].ToString());
                        msgs.Where = m_Data.UserID;
                        //msgs.What = Helpers.Helper.ConvertGB2312To8859P1(rowEvents["WFEDES"].ToString());
                        break;
                }
                //INTEXBL.CheckEvents(events, dwMaster, msg, msgs);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        private void WFAPPLY_Click(object sender, RoutedEventArgs e)
        {
            /*
            if (dwMaster == null)
            {
                MessageBox.Show("请选择采购单");
                return;
            }
            if (dwEvents == null)
            {
                MessageBox.Show("请选择需要申请的事件");
                return;
            }
            Apply(dwEvents);
            if (vwEvents.View != null)
                vwEvents.View.MoveCurrentTo(-1);
            */
        }
        private void btnWFConfirm_Click(object sender, RoutedEventArgs e)
        {
            /*
            if (dwMaster == null)
                return; 
            if (dwWFEvent == null)
                return;
            dwWFEvent["CONTROL"] = "OK ";
            dwWFEvent["CHGUSER"] = m_Data.UserID;
            dwWFEvent["CHGTIME"] = m_Data.date;
            m_Data.INTEXDBC.UpdateICC_WFEVENTS(dwWFEvent);
            string events = dwWFEvent["WFEVENTS"].ToString().Trim();
            string txtposition = "010";
            string User = m_Data.UserID;
            string date = m_Data.date;
            switch (events)
            {
                case "MYGRVKPOS001"://品质审核  
                    txtposition = "010";                  
                    break;
                case "MYGRVKPOS002"://颜色审核 
                    txtposition = "020";                   
                    break;
                case "MYGRVKPOS003"://计划备料审核 
                    txtposition = "030";
                    break;
                case "MYGRVKPOS004"://运输 
                    txtposition = "040";                   
                    break;
                case "MYGRVKPOS006"://生产  
                    txtposition = "060";                   
                    break;
                case "MYGRVKPOS005"://计划
                    txtposition = "050";                  
                    var query = from DataRow row in SetEnv.ICC_WFEVENTDEF.AsEnumerable()
                                where row["WFEVENTS"].ToString().Trim() == "MYGRVKPOS007"
                                select row;
                    foreach (DataRow row in query)
                    {
                        Apply(row);

                    }
                    foreach (DataRow row in SetData.VKPOS.Rows)
                    {
                        row["VKPLIEFTERM"] = dwMaster["VKPLIEFTERM"];
                        m_Data.INTEXDBC.UpdateVKPOS(row, "", 4);
                    }
                    break;
                case "MYGRVKPOS007"://销售
                    txtposition = "070";                   
                    break;
            }
            m_Data.SaveText(SetProd, dwMaster["VKPAUFKRS"].ToString(), dwMaster["VKPAUFLFD"].ToString(),"000", txtposition, User, date);
            */
        }

        private void btnWFReject_Click(object sender, RoutedEventArgs e)
        {
            /*
            if (dwWFEvent == null)
                return;
            dwWFEvent["CONTROL"] = "JJ";
            dwWFEvent["CHGUSER"] = m_Data.UserID;
            dwWFEvent["CHGTIME"] = Helpers.Helper.Left(System.DateTime.Now.ToString(), 20);
            m_Data.INTEXDBC.UpdateICC_WFEVENTS(dwWFEvent);
            cvMaster.CustomFilter = null;*/
        }

        private void IsQuality_Click(object sender, RoutedEventArgs e)
        {
            /*
            if (dwPTXT == null)
                return;
            CheckBox ck = sender as CheckBox;
            if (ck.Name == "IsQuality")
            {
                dwPTXT["TXT010"] = ChkQuality;
                dwPTXT["TXT010HR"] = m_Data.app.User;
                dwPTXT["TXT010DT"] = m_Data.Today;
            }
            if (ck.Name == "IsColor")
            {
                dwPTXT["TXT020"] = ChkColor;
                dwPTXT["TXT020HR"] = m_Data.app.User;
                dwPTXT["TXT020DT"] = m_Data.Today;
            }
            if (ck.Name == "IsMaterial")
            {
                dwPTXT["TXT030"] = ChkMaterial;
                dwPTXT["TXT030HR"] = m_Data.app.User;
                dwPTXT["TXT030DT"] = m_Data.Today;
            }
            if (ck.Name == "IsProd")
            {
                dwPTXT["TXT060"] = ChkProd;
                dwPTXT["TXT060HR"] = m_Data.app.User;
                dwPTXT["TXT060DT"] = m_Data.Today;
            }
            */
        }

        private void btnStartApp_Click(object sender, RoutedEventArgs e)
        {
            /*
            btnStartApp.IsEnabled = false;
            foreach (DataRow row in SetEnv.ICC_WFEVENTDEF.Rows)
            {
                string events = row["WFEVENTS"].ToString().Trim();

                switch (events)
                {
                    case "MYGRVKPOS001"://品质审核                         
                    case "MYGRVKPOS002"://颜色审核                   
                    case "MYGRVKPOS003"://计划备料审核                     
                    case "MYGRVKPOS004"://运输                  
                    case "MYGRVKPOS005"://计划                     
                    case "MYGRVKPOS006"://生产
                        Apply(row);
                        break;
                }
            }
            */
        }


    }
}
